﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HFK.DxFluentUITest.Dummy;
using MbUnit.Framework;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;

namespace HFK.DxFluentUITest.HorizontalGridControl
{
  [TestFixture]
  public class HorizontalGridControlTestFixture
  {
    [Test]
    public void TestCreation()
    {
      HorizontalGridCreation hgrid = new HorizontalGridCreation();
      GridControl horizontalGrid = hgrid.Get;

      Assert.IsNotNull(horizontalGrid);
    }

    [Test]
    public void TestAddView()
    {
      HorizontalGridWithColumns hgrid = new HorizontalGridWithColumns();
      GridControl horizontalGrid = hgrid.Get;

      Assert.IsNotNull(horizontalGrid);
      Assert.IsNotNull(horizontalGrid.MainView);
      Assert.AreEqual(1, horizontalGrid.ViewCollection.Count);
      Assert.IsInstanceOfType(typeof(GridView) ,horizontalGrid.ViewCollection[0]);
      Assert.AreEqual("View1", (horizontalGrid.ViewCollection[0] as GridView).ViewCaption);
      Assert.AreEqual(4, (horizontalGrid.ViewCollection[0] as GridView).Columns.Count);
      Assert.AreEqual("Column1", (horizontalGrid.ViewCollection[0] as GridView).Columns[0].Caption);
      Assert.AreEqual("Column2", (horizontalGrid.ViewCollection[0] as GridView).Columns[1].Caption);
      Assert.AreEqual("IntValue", (horizontalGrid.ViewCollection[0] as GridView).Columns[1].FieldName);
      Assert.AreEqual("StringValue", (horizontalGrid.ViewCollection[0] as GridView).Columns[2].FieldName);
      Assert.AreEqual("ShcData.DhcProperty.ThcProperty.StringProperty", (horizontalGrid.ViewCollection[0] as GridView).Columns[3].FieldName);
    }

    [Test]
    public void TestMasterDetail()
    {
      HorizontalGridWithMasterDetail hgrid = new HorizontalGridWithMasterDetail();
      GridControl horizontalGrid = hgrid.Get;

      Assert.IsNotNull(horizontalGrid);
      Assert.IsNotNull(horizontalGrid.MainView);
      Assert.AreEqual(2, horizontalGrid.ViewCollection.Count);

      Assert.IsInstanceOfType(typeof(GridView), horizontalGrid.ViewCollection[0]);
      Assert.AreEqual("View1", (horizontalGrid.ViewCollection[0] as GridView).ViewCaption);
      Assert.AreEqual(2, (horizontalGrid.ViewCollection[0] as GridView).Columns.Count);
      Assert.AreEqual("Column1", (horizontalGrid.ViewCollection[0] as GridView).Columns[0].Caption);
      Assert.AreEqual("Column2", (horizontalGrid.ViewCollection[0] as GridView).Columns[1].Caption);
      Assert.IsTrue(string.IsNullOrEmpty((horizontalGrid.ViewCollection[0] as GridView).Columns[0].FieldName));
      Assert.AreEqual("StringValue", (horizontalGrid.ViewCollection[0] as GridView).Columns[1].FieldName);

      Assert.IsInstanceOfType(typeof(GridView), horizontalGrid.ViewCollection[1]);
      Assert.AreEqual("DetailView1", (horizontalGrid.ViewCollection[1] as GridView).ViewCaption);
      Assert.AreEqual(2, (horizontalGrid.ViewCollection[1] as GridView).Columns.Count);
      Assert.AreEqual("Dv1Column1", (horizontalGrid.ViewCollection[1] as GridView).Columns[0].Caption);
      Assert.AreEqual("Dv1Column2", (horizontalGrid.ViewCollection[1] as GridView).Columns[1].Caption);
      Assert.IsTrue(string.IsNullOrEmpty((horizontalGrid.ViewCollection[1] as GridView).Columns[0].FieldName));
      Assert.AreEqual("StringValue", (horizontalGrid.ViewCollection[1] as GridView).Columns[1].FieldName);

      Assert.AreEqual(1, horizontalGrid.LevelTree.Nodes.Count);
      Assert.AreSame(horizontalGrid.ViewCollection[1], horizontalGrid.LevelTree.Nodes[0].LevelTemplate);
    }

    [Test]
    public void TestColumnEditable()
    {
      HorizontalGridColumnsEditable hgrid = new HorizontalGridColumnsEditable();
      GridControl horizontalGrid = hgrid.Get;

      Assert.IsNotNull(horizontalGrid);
      Assert.IsNotNull(horizontalGrid.MainView);
      Assert.AreEqual(1, horizontalGrid.ViewCollection.Count);
      Assert.IsInstanceOfType(typeof(GridView), horizontalGrid.ViewCollection[0]);
      Assert.AreEqual("View1", (horizontalGrid.ViewCollection[0] as GridView).ViewCaption);
      Assert.AreEqual(2, (horizontalGrid.ViewCollection[0] as GridView).Columns.Count);
      Assert.AreEqual("Column1", (horizontalGrid.ViewCollection[0] as GridView).Columns[0].Caption);
      Assert.AreEqual("Column2", (horizontalGrid.ViewCollection[0] as GridView).Columns[1].Caption);
      Assert.IsTrue((horizontalGrid.ViewCollection[0] as GridView).Columns[0].OptionsColumn.AllowEdit);
      Assert.IsFalse((horizontalGrid.ViewCollection[0] as GridView).Columns[1].OptionsColumn.AllowEdit);
    }
  }
}
